package com.zhiyou100.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.model.log;
import com.zhiyou100.service.LogService;

@Controller
public class LogController {
	@Autowired
	private LogService logService;
	@RequestMapping("/background/user/log")
	public String logList(@RequestParam(defaultValue="")String username,
			@RequestParam(defaultValue="")String ip,
			@RequestParam(defaultValue="1")int pageNo,Model model) {
		Map<String,Object> map = new HashMap<>();
		map.put("username", username);
		map.put("ip", ip);
		
		PageHelper.startPage(pageNo, 10);
		List<log> logs = logService.findAll(map);
		PageInfo<log> pageInfo = new PageInfo<>(logs);
		model.addAttribute("map", map);
		model.addAttribute("page", pageInfo);
		model.addAttribute("logs", pageInfo.getList());
		return "forward:/admin/view/log/backLog.jsp";
	}
	@RequestMapping("/front/user/log")
	public String frontLogList(@RequestParam(defaultValue="")String username,
			@RequestParam(defaultValue="")String ip,
			@RequestParam(defaultValue="1")int pageNo,Model model) {
		Map<String,Object> map = new HashMap<>();
		map.put("username", username);
		map.put("ip", ip);
		PageHelper.startPage(pageNo, 10);
		List<log> logs = logService.findAllLog(map);
		PageInfo<log> pageInfo = new PageInfo<>(logs);
		model.addAttribute("map", map);
		model.addAttribute("page", pageInfo);
		model.addAttribute("logs", pageInfo.getList());
		return "forward:/admin/view/log/frontLog.jsp";
	}
}
